<template>
	<el-dialog title="密钥生成对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" ref="dialogForm" label-width="80px" label-position="left">
			<el-form-item label="密钥名称">
				<span v-if="encryptionType=='0'">RSA</span>
				<span v-if="encryptionType=='1'">SM2</span>
			</el-form-item>
			<el-form-item label="公钥" prop="publicKey">
				{{form.publicKey}}
			</el-form-item>
			<el-form-item label="私钥" prop="privateKey">
				{{form.privateKey}}
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">应 用</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			encryptionType:'',
			form:{
				publicKey:'',
				privateKey:'',
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(){
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit(){
			this.visible = false;
			this.$emit('success', this.form)
		},
		//表单注入数据
		async setData(data){
			this.encryptionType=data
			let res = await this.$API.system.getEncryptionKey.get({encryptionType:this.encryptionType});
			if(res.code == 200){
				this.form.publicKey = res.data.publicKey;
				this.form.privateKey = res.data.privateKey;
			}else{
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style>
</style>
